package cheme.ProcessEditor.Figures.Util;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.graphics.Color;

import cheme.ProcessEditor.Figures.AbstractResizableGroupFig;

public class BulletedFig <T extends IFigure> extends AbstractResizableGroupFig
{
	public Color classColor = new Color(null,200,255,200);
	
	private IFigure bullet = null;
	private T contentPane = null;

	public BulletedFig(T content)
	{	
		this(content, new CircularBulletFig());
	}
	
	public BulletedFig(T content, IFigure bullet)
	{		
		layout.setVertical(false);
		layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
		layout.setSpacing(insideSpacing);
		layout.setStretchMinorAxis(false);
		
		setBullet(bullet);
		add(getBullet());

	    setContentPane(content);
		add(content);
	}
	
	public void setContentPane(T contentPane)
	{
		this.contentPane = contentPane;
	}

	public T getContentPane()
	{
		return contentPane;
	}

	private void setBullet(IFigure bullet)
	{
		this.bullet = bullet;
	}

	private IFigure getBullet()
	{
		return bullet;
	}
	
	@Override
	public Dimension getPreferredSize(int w, int h)
	{
		Dimension thumbSize = bullet.getPreferredSize(w, h);
		Dimension contentSize = contentPane.getPreferredSize(w, h);
		
		return new Dimension(thumbSize.width + contentSize.width, Math.max(thumbSize.height, contentSize.height));
	}
	
	@Override
	public Insets getInsets()
	{
		return new Insets(0,1,0,0);
	}
}
